package com.wl.mr.speak;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class SpeakBean implements Writable {

    private Long selfDuration;
    private Long thirdDuration;
    private String deviceId;
    private Long sumDuration;

    public SpeakBean(Long selfDuration, Long thirdDuration, String deviceId) {
        this.selfDuration = selfDuration;
        this.thirdDuration = thirdDuration;
        this.deviceId = deviceId;
        this.sumDuration =  selfDuration + thirdDuration;
    }


    public SpeakBean() {
    }

    public Long getSelfDuration() {
        return selfDuration;
    }

    public void setSelfDuration(Long selfDuration) {
        this.selfDuration = selfDuration;
    }

    public Long getThirdDuration() {
        return thirdDuration;
    }

    public void setThirdDuration(Long thirdDuration) {
        this.thirdDuration = thirdDuration;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public Long getSumDuration() {
        return sumDuration;
    }

    public void setSumDuration(Long sumDuration) {
        this.sumDuration = sumDuration;
    }

    @Override
    public String toString() {
        return  selfDuration + "\t" +
                thirdDuration + "\t" +
                deviceId + "\t" +
                sumDuration ;
    }

    //序列化方法：将内容输出到文本或网络中
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(selfDuration);
        out.writeLong(thirdDuration);
        out.writeUTF(deviceId);
        out.writeLong(sumDuration);

    }

    //反序列化方法:将文本或网络中的内容写入到
    @Override
    public void readFields(DataInput in) throws IOException {
        this.selfDuration = in.readLong();
        this.thirdDuration = in.readLong();
        this.deviceId = in.readUTF();
        this.sumDuration = in.readLong();
    }
}
